<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商品管理</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>

</head>
<body >
    <header class="header">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="pageTitle">商品管理</div>
        <!-- <div class="headerRight" onclick="openWin('shop_wareAdd','shop_wareAdd.html')" >添加</div> -->
    </header>
    <section class="wareManagerPage HTML_BOX">
       <div class="wareSearchBox plr displayFlex">
           <div class="wareSearch">
               <input placeholder="搜索输入商品名称" />
           </div>
           <div class="searchBtn f_c">筛选</div>
       </div>
       <ul class="orderClass displayFlex">
            <li class="on f_c">全部<i></i></li>
            <li class="f_c">上架商品<i></i></li>
            <li class="f_c">下架商品<i></i></li>
        </ul>
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <ul class="shopWareList bg-eee">
           <!--  <li id="ware_1" class="plr bg-fff">
                <div class="managerBox1 displayFlex">
                    <div>商品编号：1023566589</div>
                    <div>库存：60</div>
                </div>
                <div class="managerBox2">
                    <div class="wgImage">
                        <img src="../image/ware_1.png" />
                    </div>
                    <div class="wgInfo">
                        <div class="wgInfoBox1">广西车厘子</div>
                        <div class="wgInfoBox2">
                            <div class="wgGuiGe">2kg</div>
                            <div class="wgPrice">$62.00</div>
                        </div>
                        <div class="wgInfoBox3">
                            <div class="evaLvl ">
                                <i class="on"></i>
                                <i class="on"></i>
                                <i class="on"></i>
                                <i class="on"></i>
                                <i class="on"></i>
                                <span>(230)<span>
                            </div>
                            <del>$45.00</del>
                        </div>
                    </div>
                </div>
                <div class="managerBox1 displayFlex">
                    <div>商品分类：水果</div>
                    <div class="wmType_xj">下架中</div>
                </div>
                <div class="managerBox3 displayFlex">
                    <div class="clearTime">创建时间：07-25 17:05</div>
                    <div class="wmFunction">
                        <div class="">上架</div>
                        <div class="">编辑</div>
                        <div class="delete" data-id="1">删除</div>
                    </div>
                </div>
            </li> -->
        </ul>
        
        <div class="pageHide dn">暂无数据..</div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    
    var page =1;
    var is_shelf =0;
    var keys ="";
    var ifpage = true;
    $(".delete").click(function(){
        var id = $(this).data("id");
        deleteElement($("#ware_"+id));
    })
    $(".searchBtn").click(function(){
        keys = $("input").val();
        page =1;
        ready();
    })
    $(".orderClass li").click(function(){
        $(".orderClass li").removeClass("on");
        $(this).addClass("on");
        is_shelf = $(this).index();
        page =1;
        ready();
    })
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                 threshold: 10
            }
         }, function(ret, err) {
             //页码+1，继续请求数据
             page++;
             if(ifpage){
                ready();
             }
        });
        //兑换优惠券后回调
        api.addEventListener({
            name: 'wareAdd'
        }, function(ret, err) {
            page=1;
           ready();
        });
        ifCnAndEn();
        ready();
    };
    $(".getPage").click(function(){
        page++;
        ready();
    })
     function ready(){
        pop.loading();
        getAjax(Interface.merchant_goods,{token:token,page:page,is_shelf:is_shelf,title:keys},function(res){
           // console.log(JSON.stringify(res));
            pop.close();
            var list = res.data;
            
            if(page==1){
                $(".shopWareList").empty();
            }
            if(list){
                $(".pageHide").addClass("dn");ifpage=true;
                $(".pageHide").addClass("dn");
                $.each(list,function(i,item){
                    var name = '';
                    if(cnen==1){
                        name = item.title;
                    }else{
                        name = item.egname;
                    }
                    var is_shelf = item.is_shelf;
                    var btns = orderBtn(is_shelf,item);
                    var she_class= "wmType_sj";
                    if(is_shelf == 1){
                        is_shelf="上架中";
                        if(cnen==2){
                            is_shelf='Active';
                        }
                    }else{
                        is_shelf="下架中";
                        if(cnen==2){
                            is_shelf='Inactive';
                        }
                        she_class = 'wmType_xj';
                    }
                    var html = '<li id="" class="plr bg-fff">';
                                html +='<div class="managerBox1 displayFlex">';
                                if(cnen==1){
                                     html +='<div>商品编号：'+item.product_number+'</div>';
                                     html +='<div>库存：'+item.stock+'</div>';
                                 }else{
                                     html +='<div>Item Number：'+item.product_number+'</div>';
                                     html +='<div>Inventory：'+item.stock+'</div>';
                                 }
                                 html +='</div>';
                                 html +='<div class="managerBox2">';
                                     html +='<div class="wgImage">';
                                         html +='<img src="'+getImg(item.icon)+'" />';
                                     html +='</div>';
                                     html +='<div class="wgInfo">';
                                         html +='<div class="wgInfoBox1">'+name+'</div>';
                                         html +='<div class="wgInfoBox2">';
                                             html +='<div class="wgGuiGe"></div>';
                                             html +='<div class="wgPrice">$'+item.new_price+'</div>';
                                         html +='</div>';
                                         html +='<div class="wgInfoBox3">';
                                             html +='<div class="evaLvl ">';
                                                 var star = 0;
                                                 if(item.pinlun_num != 0){
                                                    star = Math.floor(item.star_num / item.pinlun_num);
                                                 }
                                                 if(star >5){
                                                    star = 5;
                                                 }
                                                 console.log(item.star_num);
                                                 for(var j =0;j<5;j++){
                                                    if(j<star){
                                                         html+='<i class="on"></i>';
                                                     }else{
                                                         html+='<i class=""></i>';
                                                     }
                                                   
                                                 }  
                                                html+='<span>('+item.pinlun_num+')<span>';
                                             html +='</div>';
                                             if(item.old_price!="" && item.old_price > item.new_price){
                                                html +='<del>$'+item.old_price+'</del>';
                                             }
                                         html +='</div>';
                                     html +='</div>';
                                 html +='</div>';
                                 html +='<div class="managerBox1 displayFlex">';
                                     if(cnen==1){
                                        html +='<div>商品分类：'+item.type1+'</div>';
                                     }else{
                                        html +='<div>Category：'+item.type1+'</div>';
                                     }
                                     html +='<div class="'+she_class+'">'+is_shelf+'</div>';
                                 html +='</div>';
                                 html +='<div class="managerBox3 displayFlex">';
                                 if(cnen==1){
                                    html +='<div class="clearTime">创建时间：'+timestampToTime(item.create_time)+'</div>'
                                 }else{
                                    html +='<div class="clearTime">Create：'+timestampToTime(item.create_time)+'</div>'
                                 }
                                     html +='<div class="wmFunction">';
                                         html +=btns;
                                         if(cnen==1){
                                            html +='<div onclick="modify('+item.id+')">编辑</div>';
                                         }else{
                                            html +='<div onclick="modify('+item.id+')">Edit</div>';
                                         }
                                     html +='</div>';
                                 html +='</div>';
                             html +='</li>';
                    $(".shopWareList").append(html);
                })
                if(list.length<10){
                    $(".getPage").hide();
                }
            }else{
                 ifpage=false;
                 if(page==1){$(".pageHide").removeClass("dn");}
            }
        },function(res,err){})
    }

    function modify(id){
        openWin('shop_wareAdd','shop_wareAdd.html',{id:id});
    }

    function orderBtn(type,item){
        var html ='';
        if(type == 1){
            if(cnen==1){
                html +='<div onclick="changeShelf_xj('+item.id+');">下架</div>';
            }else{
                html +='<div onclick="changeShelf_xj('+item.id+');">Inactivete</div>';
            }
        }else{
            if(cnen==1){
                html +='<div onclick="changeShelf_sj('+item.id+');">上架</div>';
            }else{
                html +='<div onclick="changeShelf_sj('+item.id+');">Activete</div>';
            }
        }
        return html;
    }

    function changeShelf_sj(id){
        event.stopPropagation();
        pop.loading();
        getAjax(Interface.changeShelf,{token:token,id:id,type:"sj"},function(res){
            pop.close();
            pop.notice(res.msg,1,function(){
                page=1;
                ready();
            });
        },function(res,err){})
    }
    function changeShelf_xj(id){
        event.stopPropagation();
        pop.loading();
        getAjax(Interface.changeShelf,{token:token,id:id,type:"xj"},function(res){
            pop.close();
            pop.notice(res.msg,1,function(){
                page=1;
                ready();
            });
        },function(res,err){})
    }

    function timestampToTime(timestamp) {
    //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var date = new Date(timestamp * 1000);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
        h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours())+ ':';
        m = (date.getMinutes()< 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
        s = date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds();
        return Y+M+D+h+m+s;
    }
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".pageTitle").eq(0).html('Manage Items');     
            $(".orderClass li").eq(0).html('All<i></i>');
            $(".orderClass li").eq(1).html('Active<i></i>');
            $(".orderClass li").eq(2).html('Inactive<i></i>');   
            $(".pageHide").html('Not data'); 
            $(".wareSearch input").attr('placeholder','Enter Item Dsscrpiption');
            $(".searchBtn").html('Filter');
        }
    }
</script>
</html>